package com.libo.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * 日期时间工具类
 */
public class DateTimeUtils {
    /**
     * 时间转换LocalDateTime
     *
     * @param time 时间戳
     * @return {@link LocalDateTime }
     */
    public static LocalDateTime timeCoverLocalDateTime(Long time){
        Instant instant = Instant.ofEpochMilli(time);
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        return LocalDateTime.ofInstant(instant, zoneId);
    }

    /**
     * LocalDateTime 本地时间日期
     * @param localDateTime
     * @return
     */
    public static long localDateTimeCoverTime(LocalDateTime localDateTime){
        return localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
    }
}